/**
 * 
 */
package mr.dividends.model;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.hadoop.io.Writable;

/**
 * @author hadoop
 * 
 */
public class DividendsInputWritable implements Writable {

	private String exchange;
	private String stockSymbol;
	private String dateStr;
	private float dividends;

	private String yearStr;
	
	/**
	 * 
	 */
	public DividendsInputWritable() {
		// TODO Auto-generated constructor stub
	}

	public DividendsInputWritable(String exchange, String stockSymbol,
			String dateStr, float dividends) {
		this.exchange = exchange;
		this.stockSymbol = stockSymbol;
		this.dateStr = dateStr;
		this.dividends = dividends;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.hadoop.io.Writable#readFields(java.io.DataInput)
	 */
	@Override
	public void readFields(DataInput input) throws IOException {
		this.exchange = input.readUTF();
		this.stockSymbol = input.readUTF();
		this.dateStr = input.readUTF();
		this.dividends = input.readFloat();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.hadoop.io.Writable#write(java.io.DataOutput)
	 */
	@Override
	public void write(DataOutput output) throws IOException {
		output.writeUTF(exchange);
		output.writeUTF(stockSymbol);
		output.writeUTF(dateStr);
		output.writeFloat(dividends);
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
	
	public String getExchange() {
		return exchange;
	}

	public void setExchange(String exchange) {
		this.exchange = exchange;
	}

	public String getStockSymbol() {
		return stockSymbol;
	}

	public void setStockSymbol(String stockSymbol) {
		this.stockSymbol = stockSymbol;
	}

	public String getDateStr() {
		return dateStr;
	}

	public void setDateStr(String dateStr) {
		this.dateStr = dateStr;
		setYearStr(getYearFromDateStr(dateStr));
	}

	public float getDividends() {
		return dividends;
	}

	public void setDividends(float dividends) {
		this.dividends = dividends;
	}

	public String getYearStr() {
		return this.yearStr;
	}

	public void setYearStr(String yearStr) {
		this.yearStr = yearStr;
	}

	public String getYearFromDateStr(String dateStr) {
		return dateStr.substring(0, 4);
	}


}
